// components/protocol/protocol.js
const app = getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        selected: {
            type: Number,
            value: ''
        }
    },
    /**
     * 组件的初始数据
     */
    data: {
        baseUrl: app.baseUrl,
        version: app.globalData.version,
        showCircle: false,
        headerUrl:'/pages/square/index',
        selected: 0,
        color: "#2C2C2C",
        selectedColor: "#2C2C2C",
        tablist: [{
            "pagePath": "/pages/index/index",
            "iconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav1_1.png",
            "selectedIconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav1_2",
            "text": ""
        }, {
            "pagePath": "/pages/brochure/index",
            "iconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav2_1.png",
            "selectedIconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav2_2.png",
            "text": ""
        }, {
            "pagePath": "/pages/circle/public/index",
            "iconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/public.png",
            "selectedIconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/public.png",
            "text": ""
        }, {
            "pagePath": "/pages/square/index",
            "iconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav4_1.png",
            "selectedIconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav4_2.png",
            "text": ""
        }, {
            "pagePath": "/pages/my/index",
            "iconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav5_1.png",
            "selectedIconPath": "https://small.andwind.cc/ly_small_24/images/bottomnav/nav5_2.png",
            "text": ""
        }],
    },

    /**
     * 组件的方法列表
     */
    methods: {
        switchTab(e) {
            console.log(e)
            const data = e.currentTarget.dataset;
            const url = data.path;
            let index = data.index;
            if (index == 2) {
                this.setData({
                    showCircle: true
                })

            } else {
                wx.switchTab({
                    url
                })
            }



        },
        //跳转发布圈子
        publicSquare() {
            this.addHeaderUrl();
            wx.redirectTo({
                url: '/pages/square/public1'
            });
        },

        //跳转发布组局
        publicPart() {
            this.addHeaderUrl();
            wx.redirectTo({
                url: '/pages/square/public2'
            });
        },
        publicYGL(){
            this.addHeaderUrl();
            wx.redirectTo({
                url: '/pages/square/public3'
            });
        },
        close() {
            this.setData({
                showCircle: false
            })
        },
        //将回跳url写入缓存
        addHeaderUrl() {
            var headerUrlList = wx.getStorageSync('headerUrlList');
            if (headerUrlList.constructor == Array) {
                if (this.data.headerUrl == headerUrlList[headerUrlList.length - 1]) {
                    //与上一个回跳链接相同则不添加
                    return;
                }
                headerUrlList.push(this.data.headerUrl);
                wx.setStorageSync('headerUrlList', headerUrlList);
            } else {
                headerUrlList = [];
                headerUrlList.push(this.data.headerUrl)
                wx.setStorageSync('headerUrlList', headerUrlList);
            }
        },

    }
})